home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Add-ons / Graphic effects / depth-switcher.c < prev    next >
Encoding:
Text File  |  1996-07-16  |  3.0 KB  |  126 lines  |  [TEXT/MACA]

  1. //**********************************
  2. //* Depth-Switcher                 *
  3. //* A SAT Add-On by:               *
  4. //*                                *
  5. //* Richard F. Bannister           *
  6. //* Titan Software                 *
  7. //* 76 Stillorgan Wood             *
  8. //* Stillorgan, Co. Dublin         *
  9. //* Republic of Ireland            *
  10. //*                                *
  11. //* http://aoife.indigo.ie/~titan/ *
  12. //* mailto:titan@indigo.ie         *
  13. //**********************************
  14.  
  15. /* Modified by Ingemar to be fully non-CQD compatible. */
  16.  
  17.  
  18. #include "SAT.h"
  19. #include "Palettes.h"
  20.  
  21. GDHandle thisGDevice;
  22.  
  23. static Boolean HasCQD(void)
  24. {
  25.         SysEnvRec               thisWorld;
  26.         
  27.         if (SysEnvirons(1, &thisWorld) != noErr) return false;
  28.         return thisWorld.hasColorQD;
  29. }
  30.  
  31. short SATGetDepth (void)
  32. {
  33.         short                   thisDepth;
  34.         char                    wasState;
  35.  
  36.         if (!HasCQD()) return 1;
  37.         
  38.         thisGDevice=GetMainDevice();
  39.  
  40.         if (thisGDevice != nil)
  41.         {
  42.                 wasState = HGetState((Handle)thisGDevice);
  43.                 HLock((Handle)thisGDevice);
  44.                 thisDepth = (**(**thisGDevice).gdPMap).pixelSize;
  45.                 HSetState((Handle)thisGDevice, wasState);
  46.         }
  47.  
  48.         return (thisDepth);
  49. }
  50.  
  51. static Boolean CanWeSwitch (GDHandle theDevice,short wantedDepth)
  52. {
  53.         short           canDepth;
  54.         Boolean         canDo;
  55.  
  56. //        if (!HasCQD()) return (wantedDepth != 1);
  57.  
  58.         canDo = FALSE;
  59.         canDepth = HasDepth(theDevice, wantedDepth, 1, 0);
  60.         if (canDepth != 0)
  61.                 canDo = TRUE;
  62.  
  63.         return (canDo);
  64. }
  65.  
  66. static void SwitchToDepth (short newDepth, Boolean doColor)
  67. {
  68.         OSErr                   theErr;
  69.         short                   colorFlag;
  70.         char                    tagByte;
  71.  
  72. //        if (!HasCQD()) return;
  73.  
  74.         if (doColor)
  75.                 colorFlag = 1;
  76.         else
  77.                 colorFlag = 0;
  78.  
  79.         if (thisGDevice != nil)
  80.         {
  81.                 tagByte = HGetState((Handle)thisGDevice);
  82.                 HLock((Handle)thisGDevice);
  83.                 theErr = SetDepth(thisGDevice, newDepth, 1, colorFlag);
  84.                 HSetState((Handle)thisGDevice, tagByte);
  85.         }
  86. }
  87.  
  88. void SATRestoreDepth (short old)
  89. {
  90.         if (!HasCQD()) return;
  91.  
  92.         thisGDevice = GetMainDevice();
  93.  
  94.         if (CanWeSwitch(thisGDevice,old))
  95.                 SwitchToDepth(old, TRUE);
  96.         else
  97.                 SysBeep(1);
  98. }
  99.  
  100. Boolean SATSetDepth (short DepthWanted)
  101. {
  102.         short wasDepth;
  103.  
  104.         if (!HasCQD()) return false;
  105.  
  106.         thisGDevice = GetMainDevice();
  107.  
  108.         wasDepth = SATGetDepth();
  109.         if (wasDepth != DepthWanted)
  110.         {
  111.                 if (CanWeSwitch(thisGDevice,DepthWanted))
  112.                 {
  113.                         SwitchToDepth(DepthWanted, TRUE);
  114.                         return true;
  115.                 }
  116.                 else
  117.                 {
  118.                         return false;
  119.                 }
  120.         }
  121.         else
  122.         {
  123.                 return true;
  124.         }
  125. }
  126.